package app.model.vos
{
	public class StateVO
	{
		public var targets:Array;
		
		
		public var order:int;
		private var _splitPath:Array;
		
		
		public function StateVO( o:Object=null)
		{
			if( o )parse( o );
		}
		
		public function addAction( action:ActionVO ):void{
			targets.push( action );
		}
		
		public function deleteAction( actionName:String ):void{
			var n:int,
				vo:ActionVO;
			while( n < targets.length ){
				vo = targets[n];
				if(vo.name == actionName){
					targets.splice(n, 1);
				};
				n++;
			}
			
		}
		
		
		
		public function contains( actionName:String ):Boolean{
				var n:int,
				vo:ActionVO;
			while( n < targets.length ){
				vo = targets[n];
				if(vo.name == actionName)return true;
				n++;
			}
			return false;
		}
		
		private function parse( o:Object ):void{
			fullPath = o.fullPath;
			order = o.order;
			targets = parseTargets( o.targets );
		
		}
		
		private function parseTargets( list:Array ):Array{
			var n:int,
				a:Array,
				o:Object;
			a=[];
			while( n < list.length ){
				o = list[n];
				a.push( new ActionVO( o.name, o.target ) );
				n++;
			}
			return a;
		}
		
		public function get fullPath():String{
			return _splitPath.join(".");
		}
		
		public function set fullPath(v:String):void{
			_splitPath = v.split(".")
		}
		
		public function get name():String{
			return _splitPath[_splitPath.length-1];
		}
		
		public function set name(v:String):void{
			_splitPath[_splitPath.length-1] = v;
		}
		
		public function get pkg():String{
			return _splitPath.slice(0, _splitPath.length-1).join(".");
		}
		
		public function get pkgArray():Array{
			return _splitPath.slice(0, _splitPath.length-1);
		}
		
		

	}
} 